/**
 * Created by Administrator on 2016/2/17.
 */
$(function () {

    function init(){
        if(config.debug){
            renderActivity(localJson.atvList);
        }else{
            getActivityInfo("atv_time");
        }
    }
    init();
    function getActivityInfo(orderType){

        $.ajax({
            url: CK.formatUrl(config.service.getActivityList),
            data: {
                orgId : config.orgId,
                orderType : orderType
            },
            type: "POST",
            async: "true",
            success: function (response) {
                if(response.code != AjaxCode.success){
                    CK.alert(response.msg);
                    return;
                }
                renderActivity(response.data);
            },
            error : function(){

            }
        });
    }

    function renderActivity(atvList){
        if(!atvList){
            var uploadActivityDivTpl = _.template($("#uploadActivityDiv").html());
            $("#atvPanel").append(uploadActivityDivTpl());
            return;
        }
        var activityInfoDivTpl = _.template($("#activityInfoDiv").html())
        _.each(atvList,function(item){
            $("#atvPanel").append(activityInfoDivTpl(item));
        });
    }

    //活动模块hover状态
    $("#atvPanel").delegate("div[name=atvDiv]","mouseenter", function () {
        var $this = $(this);
        $this.find("[name=date]").removeClass("hidden");
        $this.find("[name=location]").removeClass("hidden");
        $this.find("[name=shareCount]").removeClass("hidden");
    });

    //活动模块离开状态
    $("#atvPanel").delegate("div[name=atvDiv]","mouseleave", function () {
        var $this = $(this);
        $this.find("[name=date]").addClass("hidden");
        $this.find("[name=location]").addClass("hidden");
        $this.find("[name=shareCount]").addClass("hidden");
    });

    //活动模块点击跳转详细管理页面
    $("#atvPanel").delegate("div[name=atvDiv]","click", function () {
        var $this = $(this);
        config.manageActivity.atvId = $this.find("[name=atvId]").html();
        CK.load("html/manageActivity/activityHeader",$("#manaContainer"));
    });
});
